home *** CD-ROM | disk | FTP | other *** search
- Path: fig.leba.net!not-for-mail
- From: fweaver@leba.net
- Newsgroups: comp.lang.c
- Subject: Re: fopen not working
- Date: 20 Feb 1996 00:40:24 -0500
- Organization: LebaNet, Lebanon PA
- Sender: fweaver@fig.leba.net
- Message-ID: <4gbms8$ocg@fig.leba.net>
- NNTP-Posting-Host: fig.leba.net
-
-
- RE: FOPEN NOT WORKING
-
- From: Malcolm Smith <mjsmith@mpx.com.au>
- Reply to: Malcolm Smith
- Date: 16 Feb 1996 07:19:57 GMT
- Organization: Microplex Pty Ltd
- Newsgroups:
- comp.lang.c
- Reply to: newsgroup(s)
- References:
- <4fjnj1$4q@fig.leba.net>
-
- fweaver@leba.net wrote:
- >
- > Good evening to all C programers
- >
- > I have a problem I thought someone might be able to shed some light on
- > for me. Below is some of the code I wrote for an install program.
- >
- >
- > #include<stdio.h>
- > #include<conio.h>
- > char buf[125],stwd[110],trwd[110],*pt,*pt1;
- > int i,vr,vd;
- > FILE *in, *out;
- > main()
- > { [snip]
- >
- > instlfile("trkr.cf_","trkr.cfg");
- > instlfile("maplvl3.da_","maplvl3.dat");
- > instlfile("atpctrkr.do_","atpctrkr.doc");
- > instlfile("readme.1s_","readme.1st");
- > instlfile("file_id.di_","file_id.diz");
- >
- > [snip]
- >
- > if((in=fopen(buf,"r"))!=NULL)
- > { do{ fgets(buf,120,in);
- > pt= (char *)strstr(buf,"XXXXX");
- > if(pt!=NULL){ fclose(out); pt=pt+5;if((out=fopen(pt,"w"))==NULL)printf("ER
- ROR");
-
- ---------
- Without testing the code my best guess is that on the first pass
- through the program detects the "XXXXX" and hence tries to close
- the previous file. But there isn't one open yet.
- ---------
-
- FW- I do not think this makes any problem. If the file pointer is null
- FW- fclose will not do anything. The problem with fopen was the new line
- FW- character at the end of the pt string.
-
-
-
- > else{printf("\nInstalling %s",pt);continue; }}
- > fputs(buf,out);
- > }while(feof(in)==0);
- > }
- > }
-
- > [snip]
- >
- > instlfile(char f[15],char s[15])
- > { sprintf(buf,"%s%s",stwd,f);
- > if((in=fopen(buf,"rb"))==NULL){close(in);return(0);}
-
- ----------
- In the above line use fclose() for the corresponding fopen().
- ----------
-
- FW- Think that might have been a typo, it's changed to fclose().
-
- > if((out=fopen(s,"wb"))!=NULL)printf("\nInstalling %s",s);
- > while((i=fgetc(in))!=EOF){fputc(i,out);}
- > _fcloseall();
- > }
-
-
-
- >Regards,
-
- >Mal
-
- Floyd Weaver
-
- Internet E-Mail fweaver@leba.net
- Home page http://www.leba.net/~fweaver
-